package test;

import java.util.Scanner;

/**
 * @author oldliu
 * @since 1.0
 */
public class Chihuolianmeng {
    public static void main(String[] args) {
        final int Size = 30;
        String[] name = new String[Size];//定餐人
        String[] addr = new String[Size];//送餐地址
        String[] order = new String[Size];//定的餐的名称和份数
        int[] time = new int[Size];//送餐时间
        int[] total = new int[Size];//总价
        boolean[] state = new boolean[Size];
        //
        String foods[] = {"红烧带鱼", "鱼香肉丝", "西红柿炒鸡蛋", "水煮肉片"};
        int price[] = {29, 20, 15, 40};
        int praize[] = new int[foods.length];
        Scanner in = new Scanner(System.in);
        int count = 0;//计算器，统计当前订了几份
        int choose = 0;//用户的选择
        while (true) {
            System.out.println("*******吃货联盟订餐系统********");
            System.out.println("      1、我要订餐");
            System.out.println("      2、查看餐袋");
            System.out.println("      3、签收订单");
            System.out.println("      4、删除订单");
            System.out.println("      5、我要点赞");
            System.out.println("      6、退出系统");
            System.out.print("\n请输入功能序号：");
            choose = in.nextInt();
            if (choose == 1) {
                System.out.println("---订餐");
                System.out.println("序号  餐品   价格   点赞");
                for (int i = 0; i < foods.length; i++) {
                    System.out.print((i + 1) + " ");
                    System.out.print(foods[i] + " " + price[i] + "  " + praize[i]);
                    System.out.println();
                }
                int yourchoose = 0;
                while ((yourchoose = in.nextInt()) < 1 || yourchoose > foods.length) {
                    System.out.println("输入错误，没有这道菜");
                }
                System.out.println("定几份：");
                int fensh = 0;
                while ((fensh = in.nextInt()) < 1) {
                    System.out.println("至少要一份");
                }
                order[count] = foods[yourchoose - 1] + " " + fensh + "份";
                int rmb = price[yourchoose - 1] * fensh;
                rmb = rmb > 50 ? rmb : rmb + 5;
                total[count] = rmb;

                System.out.println("什么时间送：");
                int yourtime = 0;
                while ((yourtime = in.nextInt()) < 8 || yourtime > 20) {
                    System.out.println("送餐时间在8-20点之间");
                }
                time[count] = yourtime;
                System.out.println("送餐地址：");
                addr[count] = in.next();
                System.out.println("你的名字：");
                name[count] = in.next();
                state[count] = false;
                count++;

            } else if (choose == 2) {
                System.out.println("---查看餐袋");
                System.out.println("序号  订餐人   餐品信息  送餐日期   送餐地址   总金额   订单状态");
                for (int i = 0; i < count; i++) {
                    System.out.print((i + 1) + "  ");
                    System.out.print(name[i] + "  ");
                    System.out.print(order[i] + "  ");//！！！
                    System.out.print(time[i] + "  ");
                    System.out.print(addr[i] + "  ");
                    System.out.print(total[i] + "  ");
                    System.out.print(state[i] ? "已签收" : "已预定");
                    System.out.println();
                }
            } else if (choose == 3) {
                System.out.println("---签收");
                int qian = 0;
                System.out.print("请输入编号:");
                if((qian=in.nextInt())<1||qian>count)
                    continue;
                //                while ((qian=in.nextInt())<1||qian>count){
                //                    System.out.println("没有");
                //                }
                if (state[qian]) {
                    System.out.println("已签收！");
                } else {
                    state[qian] = true;
                    System.out.println("签收成功");
                }
            } else if (choose == 4) {
                System.out.println("---删除餐品");
                int qian = 0;
                System.out.print("请输入编号:");
                if((qian=in.nextInt())<1||qian>count)
                    continue;
                //》》》
                for(int i=qian;i<count-1;i++){
                    name[i]=name[i+1];
                    //...
                }
                //
                name[count-1]=null;
                //....
                count--;//!!!!!!!!
            } else if (choose == 5) {
                System.out.println("---点赞");
            } else if (choose == 6) {
                System.out.println("---退出");
                break;
            } else {
                System.out.println("输入错误，没有这个选项！");
            }
            System.out.println("输入0返回");
            in.next();
        }
    }
}
